var fileFieldCount = 0;

function addFileField(modelName) {
	var fields = jQuery('#attachments_fields');

	if (fields.children().length >= 10) return false;
	fileFieldCount++;

	var spanField = jQuery("<span class='field'></span>");
	spanField.append("<input type='file' name='data[Image]["+ fileFieldCount +"][attachment]' class='attachment' id='Image" + fileFieldCount + "Attachment'>");
	spanField.append("<input type='hidden' name='data[Image]["+ fileFieldCount +"][model]' value='" + modelName + "' class='model' id='Image" + fileFieldCount + "Model'>");
	spanField.append("&nbsp;<input name='data[Image][" + fileFieldCount + "][name]' class='smallinput name' placeholder='Descrição opcional' maxlength='32' type='text' id='Image" + fileFieldCount + "Name'>");
	spanField.append("&nbsp;<a href='#' onclick='removeFileField(this); return false;'><img src='/viatrip/img/delete.png' alt=''></a>");

	fields.append(spanField);

	jQuery("input:file#Image" + fileFieldCount + "Attachment").uniform();
}

function removeFileField(el) {
	var fields = jQuery('#attachments_fields');

	if (fields.children().length == 1) return false;

	jQuery(el).parent().remove();
}

function removeAttachment(el) {
	jQuery(el).parent().remove();
}